﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.CMS.MODEL;
using System.Reflection;
using System.Data.SqlClient;

namespace Jxym.wlkc2011.Module.CMS.SERVER
{
    public partial class ContentClassAdd : System.Web.UI.Page
    {
        private string _siteName = "default";
        private string _title;
        private int _parentID = 0;
        private int _id = 0;
        private object identity;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["siteName"] != null && Request.Params["Title"] != null)
                {
                    Response.HeaderEncoding = System.Text.Encoding.UTF8;
                    Response.ContentEncoding = System.Text.Encoding.UTF8;
                    Response.ContentType = "application/json";
                    Response.StatusCode = 200;

                    _siteName = Request.Params["siteName"];
                    _title = Request.Params["Title"];

                    if (Request.Params["ParentID"] != null)
                    {
                        _parentID = int.Parse(Request.Params["ParentID"]);
                    }
                    if (Request.Params["ID"] != null)
                    {
                        _id = int.Parse(Request.Params["ID"]);
                    }

                    MsSqlDal<Cms_ContentClass> iUtm = new MsSqlDal<Cms_ContentClass>();

                    if (_id != 0)
                    {
                        SqlParameter[] parameters = new SqlParameter[]{
                            new SqlParameter("@Title",_title)
                            ,new SqlParameter("@ID",_id)
                            ,new SqlParameter("@ParentID",_parentID)
                            ,new SqlParameter("@siteName",_siteName)
                        };

                        identity = iUtm.Updata(parameters);

                        Response.Write("{\"success\":true,\"msg\":\"更新完成\",\"count\":" + identity + "}");
                    }
                    else
                    {
                        SqlParameter[] parameters = new SqlParameter[]{
                            new SqlParameter("@Title",_title)
                            ,new SqlParameter("@ParentID",_parentID)
                            ,new SqlParameter("@siteName",_siteName)
                        };

                        identity = iUtm.Add(parameters);

                        Response.Write("{\"success\":true,\"msg\":\"添加完成\",\"identity\":" + identity + "}");
                    }
                    Response.End();
                }
                else
                {
                    Response.Write("{\"success\":false,\"msg\":\"参数错误\"}");
                }
            }
        }
    }
}